
import java.util.*;
public class Solution
{
    public int minmumNumberOfHost (int n, int[][] startEnd) {
        Arrays.sort(startEnd, (a, b) ->
        {
            return a[0] <= b[0] ? -1 : 1;
            //return a[0] - b[0];
        });
        PriorityQueue<Integer> heap = new PriorityQueue<>(); // ⼩根堆
        heap.offer(startEnd[0][1]);
        for(int i = 1; i < n; i++) {
            int a = startEnd[i][0], b = startEnd[i][1];
            if(a >= heap.peek())  {// ⽆重叠
                heap.poll(); heap.offer(b); }
            else  {// 有重叠
                heap.offer(b);
            }
        }
        return heap.size();
    }
}
